package cn.cmcc.online.smsapi.ui.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.Log;
import android.view.View;

import cn.cmcc.online.smsapi.ui.util.DensityUtil;

/**
 * Created by ZhangYifan on 2017/6/19.
 */

public class SmsProgressBar extends View{
    private Context mContext;
    private int progress;
    Paint mPaint;

    public SmsProgressBar(Context context) {
        super(context);
        mContext = context;
        mPaint = new Paint();
        mPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        mPaint.setColor(Color.parseColor("#aae333"));
        mPaint.setAntiAlias(true);
    }

    //设置进度
    public void setProgress(int progress) {
        this.progress = progress;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Paint paint = new Paint();
        paint.setColor(Color.parseColor("#eff0f5"));
        RectF r1 = new RectF(0, 0, DensityUtil.dp2px(mContext, 150), DensityUtil.dp2px(mContext, 12));
        int dpRectF = progress * 150 / 100;
        if (dpRectF > 150)
            dpRectF = 150;
        if (dpRectF < 0)
            dpRectF = 0;
        canvas.drawRoundRect(r1, DensityUtil.dp2px(mContext, 6), DensityUtil.dp2px(mContext, 6), paint);
        if (dpRectF >= 6 && dpRectF <= 12) {  //   6---12dp
            Log.d("wzh", "--------33" + progress * 150 / 100);
            RectF oval2 = new RectF(0, 0, DensityUtil.dp2px(mContext, 12), DensityUtil.dp2px(mContext, 12));// 设置个新的长方形，扫描测量
            canvas.drawArc(oval2, 90, 180, true, mPaint);
        } else if (dpRectF <= 150 && dpRectF > 12) { //大于12dp
            Log.d("wzh", "--------22 " + progress * 150 / 100);
            RectF r2 = new RectF(0, 0, DensityUtil.dp2px(mContext, dpRectF), DensityUtil.dp2px(mContext, 12));
            canvas.drawRoundRect(r2, DensityUtil.dp2px(mContext, 6), DensityUtil.dp2px(mContext, 6), mPaint);
        }
    }
}
